package com.blog.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//https://github.com/shuaijunlan/Autumn shiro项目
//https://blog.csdn.net/heshushun/article/details/77776706 mongodb搭建教程
//https://www.haixianhu.com/
@ComponentScan(basePackages = {
        "com.blog.boot.webapp.controller",
        "com.blog.boot.custom.aspect",
        "com.blog.boot.beetl.config",
        "com.blog.boot.service",
        "com.blog.boot.api.common",
        "com.blog.boot.mongo.db",
        "com.blog.boot.shiro"
    }
)
@EnableAutoConfiguration
@PropertySources(
        @PropertySource(value = {
                "classpath:config/myconf.properties",
                "classpath:beetl.properties",
                "classpath:config/mongodb.properties"
            }
        )
)
public class BlogWebappApplication extends WebMvcConfigurerAdapter {

    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> containerCustomizer() {

        return (container -> {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500.html");
            container.addErrorPages( error404Page, error500Page );
        });
    }
    @Override
    public void addViewControllers( ViewControllerRegistry registry ) {
        registry.addViewController( "/" ).setViewName( "forward:/index.html" );
        registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers( registry );
    }
    public static void main(String[] args) {
        SpringApplication.run(BlogWebappApplication.class, args);
    }
}
